package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类品牌中间表 前端控制器
 *
 * @author atguigu
 * @since 2022-12-24
 */
@Api(tags = "分类品牌中间表控制器")
@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;


    /**
     * 查询分类下关联的品牌列表
     *
     * @param category3Id 三级分类ID
     * @return
     */
    @GetMapping("/findTrademarkList/{category3Id}")
    public Result<List<BaseTrademark>> findTrademarkList(@PathVariable("category3Id") Long category3Id) {
        List<BaseTrademark> list = baseCategoryTrademarkService.findTrademarkList(category3Id);
        return Result.ok(list);
    }


    /**
     * 查询当前分类可选品牌列表
     * @param category3Id 三级分类ID
     * @return
     */
    @GetMapping("/findCurrentTrademarkList/{category3Id}")
    public Result<List<BaseTrademark>> findCurrentTrademarkList(@PathVariable("category3Id") Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(list);
    }


    /**
     * 将品牌关联到分类
     * @param categoryTrademarkVo
     * @return
     */
    @PostMapping("/save")
    public Result saveBasecategoryTrademark(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        baseCategoryTrademarkService.saveBasecategoryTrademark(categoryTrademarkVo);
        return Result.ok();
    }

    /**
     * 删除分类品牌关联
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    public Result removeCategoryTrademark(@PathVariable("category3Id") Long category3Id, @PathVariable("trademarkId") Long trademarkId){
        baseCategoryTrademarkService.removeCategoryTrademark(category3Id, trademarkId);
        return Result.ok();
    }
}
